﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Trident
{
    public class ErrorHandling
    {
        public static void ErrorEmail(string subject, Exception ex)
        {
            string table = string.Format(@"
<html>
  <head>
    <title>Error Reporting</title>
  </head>
  <table style=""background-color: #FFFFFF; border-collapse: collapse; padding: 1px; width: 100%; text-align: left; padding: 1"">
    <tr style=""vertical-align: top; height: 20px"">
      <td align=""right"" width=""10%"" style=""font-weight: bold;background-color: #8c8c8c; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal;color:#ba0d0d; font-size: 15px;"">Message:</td>
      <td style=""background-color: #FFFFFF; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal; font-weight: normal; font-size: 15px;"">""{0}""</td>
    </tr>
    <tr style=""vertical-align: top; height: 20px"">
      <td align=""right"" style=""font-weight: bold;background-color: #8c8c8c; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal;color:#ba0d0d; font-size: 15px;"">Source: </td>
      <td style=""background-color: #FFFFFF; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal; font-weight: normal; font-size: 15px;"">""{1}""</td>
    </tr>
    <tr style=""vertical-align: top; height: 20px"">
      <td align=""right"" style=""font-weight: bold;background-color: #8c8c8c; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal;color:#ba0d0d; font-size: 15px;"">Stack Trace: </td>
      <td style=""background-color: #FFFFFF; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal; font-weight: normal; font-size: 15px;"">""{2}""</td>
    </tr>
    <tr style=""vertical-align: top; height: 20px"">
      <td align=""right"" style=""font-weight: bold;background-color: #8c8c8c; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal;color:#ba0d0d; font-size: 15px;"">Target Site: </td>
      <td style=""background-color: #FFFFFF; border: 1px solid black; border-collapse: collapse; padding: 5px; font-family: calibri, tahoma, arial; font-style: normal; font-weight: normal; font-size: 15px;"">""{3}""</td>
    </tr>
  </table>
</html>", ex.Message, ex.Source, ex.StackTrace, ex.TargetSite); mailman.sendmail(subject, table);
        }
    }
}
